package lib.servlet;

import lib.Dao.CourseUserDAO;
import lib.Dao.Dbutil;
import lib.Dao.UserDao;
import lib.Model.Course;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import static java.lang.System.out;

/**
 * Created by ttop5 on 16-4-22.
 */
@WebServlet(urlPatterns = "/delete", name = "delete")
public class DeleteCourse extends HttpServlet{
    Dbutil dbutil = new Dbutil();
    UserDao userDao=new UserDao();
    CourseUserDAO courseUserDAO=new CourseUserDAO();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String cid = new String(req.getParameter("cid").getBytes("ISO-8859-1"), "UTF-8");
        String openId= (String) req.getSession().getAttribute("openid");



        try {

            userDao.usercourseDelete(openId,cid);
            courseUserDAO.CourseUserDelete(cid,openId);
            //req.getRequestDispatcher("/order").forward(req, resp);
            resp.sendRedirect("/orderdelete");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
